package com.ipc.app.web.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ipc.app.biz.InformationBiz;
import com.ipc.app.constants.InformationTypeConstants;
import com.ipc.app.model.Information;
import com.ipc.app.model.Paginator;

/**
 * @author haijie.zhang
 * 
 */
@Controller
@RequestMapping(value = "/jsp/between2CitiesSearch.do")
public class Between2CitiesSearchAction {

	@Autowired
	private InformationBiz informationBiz;

	@RequestMapping(method = { RequestMethod.POST, RequestMethod.GET })
	public String informationSearch(ModelMap model, String departureCity,
			String destinationCity, String index) {
		if (StringUtils.isBlank(index)) {
			index = "1";
		}
		if (StringUtils.isNotBlank(departureCity)
				&& StringUtils.isNotBlank(destinationCity)) {
			Paginator<Information> informations = informationBiz
					.getInformationBetweenCities(departureCity,
							destinationCity,
							InformationTypeConstants.CAR_OWNER, Integer
									.valueOf(index));
			model.addAttribute("departureCity", departureCity);
			model.addAttribute("destinationCity", destinationCity);
			model.addAttribute("informations", informations);
		}

		return "between2CitiesSearch";
	}

}
